Ext.Msg.buttonText.ok=_('Ok');    

Verbum.Registration = function() {

	Ext.QuickTips.init();

	var langStore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: getMainUrl(),
			method: 'POST'
			}),
			baseParams: {action: 'system_list', op: 'lang'},
		reader: new Ext.data.JsonReader({
			root: 'results'
		},[
			{name: 'name'},
			{name: 'value'},
		]),
		sortInfo: {field: 'name',direction:'ASC'}
	});

	langStore.load();
	
	var timeStore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: getMainUrl(),
			method: 'POST'
			}),
			baseParams: {action: 'system_list', op: 'timezone'},
		reader: new Ext.data.JsonReader({
			root: 'results'
		},[
			{name: 'name'},
			{name: 'value'},
		])
	});
	
	timeStore.load();
	
    var regForm = new Ext.form.FormPanel({
        baseCls: 'x-plain',
        labelWidth: 120,
        url:getMainUrl(),
        defaultType: 'textfield',
        buttonAlign:'right',
        waitMsgTarget: true,
        autoHeight: true,
        defaults: {msgTarget:'side', allowBlank: false}, 
        items: [{
            fieldLabel: _('Username'),
            name: 'userid',
            blankText: _('Please, enter desired Username.'),
            maxLength: 20,
            minLength: MULEN,
            vtype: 'alphanum'
        },{
            fieldLabel: _('Real name'),
            name: 'name',
            maxLength: 50
        },{
            fieldLabel: _('e-mail'),
            name: 'mail',
            id: 'mail',
            inputType: 'email',
            blankText: _('Please, enter your e-mail address.'),
        	vtype: 'email',
        	value: useMail
        },{
            fieldLabel: _('Confirm e-mail'),
            name: 'mailconf',
            inputType: 'email',
            blankText: _('Please, confirm your e-mail address.'),
        	vtype: 'equal',
        	vtypeText: _('The e-mail and its verification does not match.'),
        	cmpField: 'mail',
        	value: useMail
		},{
		    xtype:"textfield",
			fieldLabel: _('Password'),
			name:"password",
			inputType:"password",
			id:"password",
			minLength: MPLEN
		},{
		    xtype:"textfield",
			fieldLabel: _('Confirm Password'),
			name:"confpassword",
			inputType:"password",
			vtype: "password",
			initialPassField: "password"
        },{
            fieldLabel: _('Team'),
        	value: useTeam,
        	disabled: true,
        	allowBlank: true
        },{
	        xtype:'combo',
	        fieldLabel: _('Language'),
	        hiddenName:"langid",
	        blankText: _('Please, select the desired language.'),
	        store: langStore,
	        forceSelection: true,
	        triggerAction: 'all',
	        listWidth: 150,
	        displayField: 'name',
	        valueField: 'value',
	        mode: 'local'
        },{
	        xtype:'combo',
	        fieldLabel: _('Time Zone'),
	        hiddenName:"timezone",
			tpl: '<tpl for="."><div ext:qtip="{name}" class="x-combo-list-item">{name}</div></tpl>',
	        blankText: _('Please, select your time zone.'),
	        store: timeStore,
	        forceSelection: true,
	        triggerAction: 'all',
	        listWidth: 150,
	        displayField: 'name',
	        valueField: 'value',
	        mode: 'local'
        }],
       buttons:[{ 
                text: _('Create account'),
                handler:function(){ 
					if (regForm.getForm().isValid()) {
	                    regForm.getForm().submit({ 
	                        method:'POST', 
	                        waitTitle:_('Sending...'), 
	                        waitMsg: _('Sending...'),
	                        params: {action: 'user_reg_control', auth: tempId, teamid: teamId},
	 
	                        success:function(form, action){
	                        	obj = Ext.util.JSON.decode(action.response.responseText);
								Ext.Msg.show({
											title: _('Verbum'),
											msg: 'Your user has been created. Please, check your mailbox to complete the process.',
											buttons: Ext.Msg.OK,
											icon: Ext.Msg.INFO,
											fn: function() {
												window.location = obj.ret;											
												regWindow.close();											
											}
										})                        	
	                        },
	 
	                        failure:function(form, action){ 
	                            if(action.failureType == 'server'){ 
	                                Ext.Msg.alert(_('Warning!'), _('Server is unreachable: ') + action.response.responseText);
	                            } else {
	                            	if (action.response != undefined) {
		                            	obj = Ext.util.JSON.decode(action.response.responseText);  
		                                Ext.Msg.alert(_('Registration Failed!'), obj.error); 
	                            	}
	                            } 
	                        } 
	                    }); 						
					}
                } 
            }] 
    });

    var regWindow = new Ext.Window({
        title: _('User Registration'),
        width: 400,
        height:290,
        minWidth: 300,
        minHeight: 270,
        layout: 'fit',
        bodyStyle:'padding:5px;',
        items: regForm,
		resizable: false,
		closable: false,
		draggable: false
    });

    regWindow.show();
    
};

Ext.onReady(Verbum.Registration());